import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 用户设置相关
class HttpSettingService {
  /// 获取设置数据
  static Future<Response> getSettingData() {
    return BaseConfig.httpBase.get('/api/setting/data', {});
  }

  static Future<Response> getSettingPaymentTerm() {
    return BaseConfig.httpBase
        .get('/api/setting/preferences/payment/terms', {});
  }

  /// 获取设置信息
  static Future<Response> getSettingApp() {
    return BaseConfig.httpBase.get('/api/setting/app', {});
  }

  /// 获取设置模板
  static Future<Response> getSettingTemplates() {
    return BaseConfig.httpBase.get('/api/setting/templates', {});
  }

  /// 更新用户信息
  static Future<Response> updateMyProfile() {
    return BaseConfig.httpBase.putJson('/api/users/me', {});
  }

  /// 用户配置
  static Future<Response> getSettingInfo() {
    return BaseConfig.httpBase.get('/api/setting/preferences', {});
  }

  /// 薪资类型
  static Future<Response> getIncomeType() {
    return BaseConfig.httpBase.get('/api/setting/income_types', {});
  }

  /// 更新用户配置
  static Future<Response> updateSettingInfo({
    String language,
    String default_currency_code,
    int default_payment_type_id,
    int default_payment_term_id,
    int tax_id,
    String date_format,
    List<String> alerts,
  }) {
    return BaseConfig.httpBase.postJson('/api/setting/preferences', {
      "language": language,
      "default_currency_code": default_currency_code,
      "default_payment_type_id": default_payment_type_id,
      "default_payment_term_id": default_payment_term_id,
      "tax_id": tax_id,
      "date_format": date_format,
      "alerts": alerts
    });
  }

  /// 更新用户配置
  static Future<Response> updatePreferenceNumber(
    int id, {
    String prefix,
    String digit,
  }) {
    return BaseConfig.httpBase.postJson('/api/setting/preferences/numbers/$id',
        {"prefix": prefix, "digit": digit});
  }

  /// 获取时间
  /// type 有以下这些值quotation，invoice，purchase_order，bill，expense，credit_note，debit_note，
  /// money_out，money_in，transfer，payslip，cpf_contribution，gst_f5，payslip_list,
  /// report -- aged_receivables 和 inventory_valuation_summary
  static Future<Response> getSuggestTime(String type) {
    return BaseConfig.httpBase.get('/api/setting/date/$type', {});
  }
}
